﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../CSS/style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        //添加一个角色
        function showAdd() {
            $.showModalDialog("roleManagerAdd.htm", null, 350, 180, function (r) {
                Load();
            })
        }
        //修改一个角色
        function showEdit(id) {
            $.showModalDialog("roleManagerEdit.htm", {id:id}, 350, 250, function (r) {
                //判断有没有修改成功
                if (r) {
                    //修改成功，刷新列表
                    Load();
                }
            })
        }
        //删除一个角色
        function showDelete(id) {
            //询问
            if (!confirm("确认删除吗？")) return;
            $.ajax({
                url: "roleManager.asmx/DeleteRole",
                type: "post",
                data: JSON.stringify({ id: parseInt(id) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "删除成功" : "删除失败");
                    //刷新
                    Load();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
        function xiao() {
            $("#tab tr:gt(0)").live("click", function () {

                $("#dataDiv .dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "green");

            });
        }
        $(function () {
            Load();
            xiao();
        })
        //用于刷新的
        function Load() {
            $.ajax({
                url: "roleManager.asmx/SelectRole",
                type: "post",
                data: JSON.stringify({}),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    var data = obj.d;
                    $("#tab tr:gt(0)").remove();
                    var tab = $("#tab").get(0);
                    for (var i = 0; i < data.length; i++) {
                        var tr = tab.insertRow(-1);
                        tr.insertCell(-1).innerHTML = data[i].ID;
                        tr.insertCell(-1).innerHTML = data[i].RoleName;
                        tr.insertCell(-1).innerHTML = "<img title='修改' src='../images/33.gif' onclick='showEdit(" + data[i].ID + ");' /><img title='删除' src='../images/11.gif' onclick='showDelete(" + data[i].ID + ");' />";
                    }

                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
    </script>
</head>
<body>
<div id="desDiv">
    <span>角色管理</span><br />
    创建和维护系统中的角色
</div>
<div id="dataDiv">
    <div id="headDiv">
        <img src="../images/22.gif" />&nbsp;&nbsp;<a href="javascript:showAdd()">新建</a>
    </div>
    <table class="dataTable" id="tab">
        <tr>
            <th width="140">角色编号</th>
            <th>角色名称</th>
            <th width="200">操作</th>
        </tr>
    </table>
    <div id="pageDiv">
        &nbsp;
    </div>
</div>
</body>
</html>
